import React, { Component } from 'react';

class ExchangeRate extends Component {

    componentDidMount() {
        this.interval = setTimeout(this.onEnded, this.props.media.playTime * 1000)
    }

    componentWillReceiveProps(nextProps) {
        console.log(nextProps.media.time,"nextProps")
        clearInterval(this.interval)
        this.interval = setTimeout(this.onEnded, nextProps.media.playTime * 1000)
    }

    componentWillUnmount() {
        clearInterval(this.interval)
    }

    onEnded = () => {
        this.props.startNextMedia()
    }

    render() {
        return (
            <div className="exchangeRate" style={{ "backgroundImage": "url(static/image/huilv.png)", }}>
                <div className="publishTime">发布时间:<span>{this.props.media.list&&this.props.media.list[0].PublishTime}</span></div>
                <ul>
                    {this.props.media.list&&this.props.media.list.map((item, i) =>
                        <li key={i} className="list">
                            <div className="name">{item.Name}</div>
                            <div className="info">
                                <div className="currencySale"><span>现汇买入价</span><span>{item.CurrencyBuy?item.CurrencyBuy:'-'}</span></div>
                                <div className="cashSale"><span>现汇卖出价</span><span>{item.CashSale?item.CashSale:'-'}</span></div>
                                <div className="convert"><span>中间折算价</span><span>{item.Convert?item.Convert:'-'}</span></div>
                            </div>

                        </li>
                    )}
                </ul>


            </div>
        )
    }
}

export default ExchangeRate;
